<template>
  <el-switch
    size="mini"
    v-model="val"
    :disabled="disabled"
    :name="config.name"
    :validate-event="config.validate"
    @change="change"
  ></el-switch>
</template>
<script>
// import { Switch } from "element-ui";
import control from '@/mixins/control'
export default {
  mixins: [control],
  // components: {
  //   elSwitch: Switch,
  // },
  data(){
    return {
      val:false
    }
  },
  created() {
    if (this.value === null || typeof this.value === 'undefined') {
      this.val = false
    } else {
      console.log(this.value, typeof this.value, 'switch是啥')
      this.val = this.value
    }
  },
  watch: {
    value(val) {
      if(val === '0'){
        this.val = false
      }
      if(val === '1'){
        this.val = true
      }
    }
  },
  methods: {
    change(e) {
      this.config && this.config.change && this.config.change(e)
    },
    getValue() {
      return this.returnValue;
    },
    setValue(val) {
      $c.log(2, val)
      this.val = val;
    }
  },
  computed: {
    returnValue() {
      return this.val
    },
    disabled() {
      return this.config.disabled
    }
  }
}
</script>
